@isTest
/***
* Bhumika Udani    v2.0  dt 30 November 2011            Updated the class as per req 873
*
**/

Private class iFulfillMoveBackControllerTest{


    static testMethod void test_Workflow(){  
    
     QueueSObject q = null;
     QueueSObject q1 = null;
     QueueSObject q2 = null;


     Profile p = [select id from profile where name='System Administrator'];      
     User u = new User(alias = 'sysad', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='Tes12', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testad123@testorg.com');      
     Insert u;    
     
     System.runAs(u){        
     Group g = new Group(Type='Queue', Name='Queue007');               
     insert g;
     
     Group g1 = new Group(Type='Queue', Name='Queue008');               
     insert g1;
     
     Group g2 = new Group(Type='Queue', Name='Queue009');  
     insert g2;               
     
     system.debug('group idddddddddddd'+g.id);               
     q = new QueueSObject(SobjectType='Fullfilment_Item__c', QueueId=g.Id); 
     insert q;
     
     q1 = new QueueSObject(SobjectType='Fullfilment_Item__c', QueueId=g1.Id); 
     insert q1;

     q2 = new QueueSObject(SobjectType='Fullfilment_Item__c', QueueId=g2.Id); 
     insert q2;

     }
             
    /**Creating workflow definition**/
    
    Workflow_definition__c wfd = new Workflow_definition__c();
           wfd.Status__c = 'Active';
           wfd.Workflow_Name__c = 'WF';
           insert wfd;
           
   List<Assignment_Group_Name__c> AGlist = new list<Assignment_Group_Name__c>(); 
    Assignment_Group_Name__c AG = new Assignment_Group_Name__c();
                 AG.name = 'AG1';
                 AG.Function__c = 'Advertiser Approval';
                 AG.Type__c = 'Fulfillment';
                 AG.Description__c = 'Description';            
                 AG.Round_Robin__c = true;            
                 AGlist.add(AG);
                 
    Assignment_Group_Name__c AG1 = new Assignment_Group_Name__c();
                 AG1.name = 'AG for Stage 1';
                 AG1.Function__c = 'Advertiser Approval 1';
                 AG1.Type__c = 'Fulfillment';
                 AG1.Description__c = 'Description 1';            
                 AG1.Round_Robin__c = false;            
                 AGlist.add(AG1);
                 
    Assignment_Group_Name__c AG2 = new Assignment_Group_Name__c();
                 AG2.name = 'AG for Stage 2';
                 AG2.Function__c = 'Advertiser Approval 2';
                 AG2.Type__c = 'Fulfillment';
                 AG2.Description__c = 'Description 2';            
                 AG2.Round_Robin__c = false;     
                 AGlist.add(AG2);       
                 insert AGlist;                          
                 
    /**function pre Definitions **/
    List<Stage_Definition__c> stgList = new list<Stage_Definition__c>();
    Stage_Definition__c preD1 = new Stage_Definition__c();            
                preD1.name = 'East';            
                preD1.Stage_Description__c = 'Desc';
                preD1.Sequence__c = 52.0;            
                preD1.Status__c = 'Active';            
                stgList.add(preD1);
    
    
    Stage_Definition__c preD2= new Stage_Definition__c();            
            preD2.name = 'Advertiser Approval';            
            preD2.Stage_Description__c = 'Desc 3555';            
            preD2.Sequence__c = 50.0;            
            preD2.Status__c = 'Active';            
            stgList.add(preD2);        
        
    Stage_Definition__c preD3= new Stage_Definition__c();            
            preD3.name = 'Writing Copy';            
            preD3.Stage_Description__c = 'Desc 3';            
            preD3.Sequence__c = 51.0;            
            preD3.Status__c = 'Active';            
            stgList.add(preD3);
            insert stgList; 
        
                                    
    /**Adding Functions**/
     List<Workflow_Stage__c> WFSList = new list<Workflow_Stage__c>();   
       Workflow_Stage__c WFS = new Workflow_Stage__c();
            WFS.name = 'Advertiser Approval';
            WFS.Workflow_Code__c = wfd.id;
            WFS.Sequence__c = 1.0;
            WFS.Stage__c = preD1.id; 
                         
       Workflow_Stage__c WFS1 = new Workflow_Stage__c();
            WFS1.name = 'Advertiser Approval 2';
            WFS1.Workflow_Code__c = wfd.id;
            WFS1.Sequence__c = 2;
            WFS1.Stage__c = preD2.id;
                        
       Workflow_Stage__c WFS2 = new Workflow_Stage__c();
            WFS2.name = 'Advertiser Approval 3';
            WFS2.Workflow_Code__c = wfd.id;
            WFS2.Sequence__c = 3;
            WFS2.Is_Last_Function__c=true;
            WFS2.Stage__c = preD3.id;

            WFSList.add(WFS);
            WFSList.add(WFS1);
            WFSList.add(WFS2); 
            insert WFSList;

       WF_Assignment_Group__c WAG = new WF_Assignment_Group__c();            
               WAG.Workflow_Function__c = WFS.id;            
               WAG.AG_Definition__c = AG.id;                        
    
       WF_Assignment_Group__c WAG1 = new WF_Assignment_Group__c();
                WAG1.Workflow_Function__c = WFS1.id;            
                WAG1.AG_Definition__c = AG1.id;     
       
       WF_Assignment_Group__c WAG2 = new WF_Assignment_Group__c();
                WAG2.Workflow_Function__c = WFS2.id;            
                WAG2.AG_Definition__c = AG2.id;                             
    
    List<WF_Assignment_Group__c> WAGlist= new list<WF_Assignment_Group__c>();
              WAGlist.add(WAG);
              WAGlist.add(WAG1);
              WAGlist.add(WAG2);                           
              insert WAGlist;

    Assignment_Group_Queues__c AGQ = new Assignment_Group_Queues__c();            
            AGQ.Name = 'Queue007';            
            AGQ.Active__c = 'True';            
            AGQ.Assignment_Group_Name__c = AG.id;            
            AGQ.Valid_Queue__c = true;            
            AGQ.QueueId__c = q.id;
                
   Assignment_Group_Queues__c AGQ1 = new Assignment_Group_Queues__c();            
            AGQ1.Name = 'Queue008';            
            AGQ1.Active__c = 'True';            
            AGQ1.Assignment_Group_Name__c = AG1.id;            
            AGQ1.Valid_Queue__c = true;            
            AGQ1.QueueId__c = q1.id;
                  
    Assignment_Group_Queues__c AGQ2 = new Assignment_Group_Queues__c();            
            AGQ2.Name = 'Queue009';            
            AGQ2.Active__c = 'True';            
            AGQ2.Assignment_Group_Name__c = AG2.id;            
            AGQ2.Valid_Queue__c = true;            
            AGQ2.QueueId__c = q2.id;
            
list<Assignment_Group_Queues__c>  AGQlist = new list<Assignment_Group_Queues__c>();
            AGQlist.add(AGQ); 
            AGQlist.add(AGQ1);
            AGQlist.add(AGQ2);
            insert AGQlist;
         
    //Adding tasks to Functions
    Wokflow_Steps__c wfSteps1 = new Wokflow_Steps__c();
            wfSteps1.name = 'Final Verification';
            wfSteps1.Wokflow_Stage_Name__c = WFS.id;
            wfSteps1.Target_Days__c = 12;
            wfSteps1.Dashboard_Function__c ='Design';
            wfSteps1.Default_Group__c = AG.id; 
            wfSteps1.Sequence__c=1.0;

      
      Wokflow_Steps__c wfSteps2 = new Wokflow_Steps__c();
            wfSteps2.name = 'Final Verification';
            wfSteps2.Wokflow_Stage_Name__c = WFS1.id;
            wfSteps2.Target_Days__c = 2;
            wfSteps2.Dashboard_Function__c ='Vendor Keying';
            wfSteps2.Default_Group__c = AG1.id; 
            wfSteps2.Sequence__c=1.0;
            
            
      Wokflow_Steps__c wfSteps3 = new Wokflow_Steps__c();
            wfSteps3.name = 'Final Verification';
            wfSteps3.Wokflow_Stage_Name__c = WFS2.id;
            wfSteps3.Target_Days__c = 4;
            wfSteps3.Dashboard_Function__c = 'Final Verification';
            wfSteps3.Default_Group__c = AG2.id; 
            wfSteps3.Sequence__c = 1.0;
            
      
      Wokflow_Steps__c wfSteps4 = new Wokflow_Steps__c();
            wfSteps4.name = 'Final Verification';
            wfSteps4.Wokflow_Stage_Name__c = WFS2.id;
            wfSteps4.Target_Days__c = 3;
            wfSteps4.Dashboard_Function__c = 'Proofing';
            wfSteps4.Sequence__c=2.0;
            wfSteps4.Default_Group__c = AG2.id; 
            wfSteps4.Is_Last_Task__c= true;
            
      list<Wokflow_Steps__c> wfStepsList = new list<Wokflow_Steps__c>();
      wfStepsList.add(wfSteps3); 
      wfStepsList.add(wfSteps2); 
      wfStepsList.add(wfSteps1);             
      insert wfStepsList;
            
    
      Fullfilment_Item__c FI = new Fullfilment_Item__c();
       FI.Current_Stage__c = WFS.id;
       FI.Workflow_Code__c = wfd.id;
       system.runAs(u){
       insert FI;
              
       FI.Status__c='Open';
       FI.ownerID = u.id;
       Update FI;
       
       
       FI.Current_Stage__c=WFS2.id;
       FI.Current_Step__c =wfSteps4.id; 
       update FI;
       }
       
       ApexPages.StandardController StdCtrl = new ApexPages.StandardController(FI);
       iFulfillMoveBackController controller = new iFulfillMoveBackController(StdCtrl);
     
         controller.selstep = wfSteps1.id;
         controller.selStage = WFS.id;
         controller.previousTask();
         controller.dummy();
         controller.assignUserAsOwner =false;
         controller.Previousfunction();
         controller.newInstructionRecord();
         controller.previousTask();
         

    }
 }